var async = require('async');
var bookingService = rootRequire('services/bookingService')

module.exports =  function(server){

    server.route({
        method:'post',path:'/select-room',
        handler:function(req,reply){
            //var hotelno = req.query['hn'],
            //    rtCode = req.query['rtCode'],
            //    orderNum = req.query['orderNum']
            //    {
            //    hotelno:hotelno,
            //    rtCode:rtCode,
            //    orderNum:orderNum
            //}
            var payload = req.payload;

            bookingService.selectRoom(payload,function(err,body){
                console.log(err)
                console.log(body)
                if(err){
                    return reply({
                        error:'获取选房列表失败',
                        reason:err
                    })
                }
                var roomList = body.rmlist;
                reply({roomList:roomList})
            })
        }
    })

    server.route({
        method:'post',path:"/submit-room",
        handler:function(req,reply){
            var payload = req.payload
            bookingService.submitRoom(payload,function(err,body){
                if(err){
                    return reply({
                        error:'提交选房失败',
                        reason:err
                    })
                }
                //console.log(body)
                reply(body);
            })
        }
    })

}